/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlinganhang.view;

import java.awt.Color;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableColumnModel;
import org.jdesktop.swingx.JXTableHeader;
import org.jdesktop.swingx.decorator.ColorHighlighter;
import org.jdesktop.swingx.decorator.HighlightPredicate;
import org.jdesktop.swingx.decorator.HighlighterFactory;
import quanlinganhang.dao.RuleDAO;
import quanlinganhang.model.RuleTableModel;

/**
 *
 * @author phamduong
 */
public class FromRules extends javax.swing.JPanel {

    /**
     * Creates new form FromRules
     */
    public FromRules() {
        initComponents();
        LoadInfo();
    }

    /**
     * Money
     * @param t
     * @return
     */
    private String FormatMoneyString(String t) {
        //định dạng tiền tệ
        NumberFormat formatter = new DecimalFormat("#,###.###");
        t = t.substring(0, t.indexOf("."));
        t = formatter.format(Double.parseDouble(t));
        return t;
    }

    /**
     * Load thông tin vào form
     */
    private void LoadInfo() {
        try {
            List t;
            t = new ArrayList(RuleDAO.getRules());

            String DuToiThieu = ((ArrayList) t.get(0)).get(0).toString();
            DuToiThieu = FormatMoneyString(DuToiThieu);
            txtDuToiThieu.setText(DuToiThieu);

            String TienGuiToiThieu = ((ArrayList) t.get(0)).get(1).toString();
            TienGuiToiThieu = FormatMoneyString(TienGuiToiThieu);
            txtGuiToiThieu.setText(TienGuiToiThieu);

            String TienRutToiThieu = ((ArrayList) t.get(0)).get(4).toString();
            TienRutToiThieu = FormatMoneyString(TienRutToiThieu);
            txtRutToiThieu.setText(TienRutToiThieu);

            String SoLanRutToiDa = ((ArrayList) t.get(0)).get(2).toString();
            txtSoLanRutDa.setText(SoLanRutToiDa);

            String TienRutToiDaGD = ((ArrayList) t.get(0)).get(5).toString();
            TienRutToiDaGD = FormatMoneyString(TienRutToiDaGD);
            txtSoTienRutToiDa.setText(TienRutToiDaGD);

            String TienToiDaNgay = ((ArrayList) t.get(0)).get(3).toString();
            TienToiDaNgay = FormatMoneyString(TienToiDaNgay);
            txtSoTienRutToiDaNgay.setText(TienToiDaNgay);

            tblLoaiTaiKhoan.setModel(new RuleTableModel());

            tblLoaiTaiKhoan.setHighlighters(HighlighterFactory.createSimpleStriping());

            tblLoaiTaiKhoan.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            //set màu sắc của row khi cuộn qua (màu background của row và màu text của row)
            tblLoaiTaiKhoan.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW,
                    null, new Color(255, 102, 0)));
            //nếu không chọn 1 row nào thì 2 button Sửa và Xóa sẽ disable
            
            TableColumnModel columnModel = tblLoaiTaiKhoan.getColumnModel();
            tblLoaiTaiKhoan.setTableHeader(new JXTableHeader(columnModel) {
                @Override
                public void updateUI() {
                    super.updateUI();
                    // need to do in updateUI to survive toggling of LAF 
                    if (getDefaultRenderer() instanceof JLabel) {
                        ((JLabel) getDefaultRenderer()).setHorizontalAlignment(JLabel.CENTER);
                    }
                }
            });
            //cột Mã người dùng có màu và căn giữa
            tblLoaiTaiKhoan.getColumn(0).setCellRenderer(new MyTableRenderer.IDRenderer());
            //Cột  Mật khẩu đổi qua màu xanh
            tblLoaiTaiKhoan.getColumn(2).setCellRenderer(new MyTableRenderer.ColorRenderer());

//        filterController = new MyTableFilter(tblLoaiTaiKhoan);
//        BindingGroup filterGroup = new BindingGroup();
//        filterGroup.addBinding(Bindings.createAutoBinding(READ,
//                txtSearch, BeanProperty.create("text"),
//                filterController, BeanProperty.create("filterString")));
//        filterGroup.bind();

        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(FromRules.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblLoaiTaiKhoan = new org.jdesktop.swingx.JXTable();
        jLabel7 = new javax.swing.JLabel();
        txtDuToiThieu = new javax.swing.JTextField();
        txtSoLanRutDa = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtGuiToiThieu = new javax.swing.JTextField();
        txtRutToiThieu = new javax.swing.JTextField();
        txtSoTienRutToiDa = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtSoTienRutToiDaNgay = new javax.swing.JTextField();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());

        tblLoaiTaiKhoan.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblLoaiTaiKhoan);

        jTabbedPane1.addTab("Các loại tài khoản", jScrollPane1);

        jLabel7.setText("Số tiền rút tối đa/Giao dịch");

        txtDuToiThieu.setEditable(false);

        txtSoLanRutDa.setEditable(false);

        jLabel6.setText("Số lần rút tối đa/ngày");

        jLabel1.setText("Số dư tối thiểu");

        jLabel3.setText("Số tiền gửi tối thiểu");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(0, 102, 153));
        jLabel2.setText("Thay đổi quy định");

        txtGuiToiThieu.setEditable(false);

        txtRutToiThieu.setEditable(false);

        txtSoTienRutToiDa.setEditable(false);

        jLabel5.setText("Số tiên rút tối đa/ngày");

        jLabel4.setText("Số tiền rút tối thiểu");

        txtSoTienRutToiDaNgay.setEditable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3))
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtDuToiThieu)
                            .addComponent(txtGuiToiThieu, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(28, 28, 28)
                        .addComponent(txtRutToiThieu, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtSoTienRutToiDa, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtSoLanRutDa, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(28, 28, 28)
                        .addComponent(txtSoTienRutToiDaNgay, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(46, 46, 46))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(207, 207, 207)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 686, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtDuToiThieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtGuiToiThieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtRutToiThieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtSoLanRutDa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(txtSoTienRutToiDa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtSoTienRutToiDaNgay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private org.jdesktop.swingx.JXTable tblLoaiTaiKhoan;
    private javax.swing.JTextField txtDuToiThieu;
    private javax.swing.JTextField txtGuiToiThieu;
    private javax.swing.JTextField txtRutToiThieu;
    private javax.swing.JTextField txtSoLanRutDa;
    private javax.swing.JTextField txtSoTienRutToiDa;
    private javax.swing.JTextField txtSoTienRutToiDaNgay;
    // End of variables declaration//GEN-END:variables
}
